package vistas;

import controladores.Controlador;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.List;
import javax.swing.JOptionPane;
import vistas.estructuras.ContenedorCiudad;


public class VentanaJuegoPrincipal extends javax.swing.JFrame implements InterfazJuegoPrincipal {
    private ContenedorCiudad ciudad;

    

    /**
     * Creates new form VentanaJuegoPrincipal
     */
    public VentanaJuegoPrincipal() {
        initComponents();
        setSize(900, 700);        
        setLocationRelativeTo(null);
        ciudad = new ContenedorCiudad();
                
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        volver = new javax.swing.JButton();
        saludo = new javax.swing.JLabel();
        partida = new javax.swing.JLabel();
        puntaje = new javax.swing.JLabel();
        movimientosMaximos = new javax.swing.JLabel();
        movimientosActuales = new javax.swing.JLabel();
        vehiculoActual = new javax.swing.JLabel();
        guardar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        flechaNorte = new javax.swing.JButton();
        flechaSur = new javax.swing.JButton();
        flechaEste = new javax.swing.JButton();
        flechaOeste = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Juego - Pantalla Principal");
        setPreferredSize(new java.awt.Dimension(763, 400));

        jPanel1.setBackground(java.awt.Color.black);

        volver.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        volver.setText("Volver");

        saludo.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        saludo.setForeground(new java.awt.Color(255, 255, 255));

        partida.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        partida.setForeground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(saludo, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(99, 99, 99)
                .addComponent(partida, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 144, Short.MAX_VALUE)
                .addComponent(volver, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(volver, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(saludo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(partida, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        puntaje.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        movimientosMaximos.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        movimientosActuales.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        vehiculoActual.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        guardar.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        guardar.setText("Guardar Partida");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        flechaNorte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/estructuras/imagenes/Flechas/Flecha hacia arriba.png"))); // NOI18N
        flechaNorte.setActionCommand("Conducir al Norte");

        flechaSur.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/estructuras/imagenes/Flechas/Flecha hacia abajo.png"))); // NOI18N
        flechaSur.setActionCommand("Conducir al Sur");

        flechaEste.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/estructuras/imagenes/Flechas/Flecha hacia derecha.png"))); // NOI18N
        flechaEste.setActionCommand("Conducir al Este");

        flechaOeste.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/estructuras/imagenes/Flechas/Flecha hacia izquierda.png"))); // NOI18N
        flechaOeste.setActionCommand("Conducir al Oeste");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(movimientosMaximos, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(vehiculoActual, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(puntaje, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(flechaOeste, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(flechaEste, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(flechaNorte)
                        .addComponent(flechaSur))
                    .addComponent(guardar, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(movimientosActuales, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(movimientosActuales, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(vehiculoActual, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(movimientosMaximos, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(puntaje, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(85, 85, 85)
                        .addComponent(flechaNorte)
                        .addGap(4, 4, 4)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(flechaEste)
                            .addComponent(flechaOeste))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(flechaSur)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 93, Short.MAX_VALUE)
                        .addComponent(guardar))
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentanaJuegoPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentanaJuegoPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentanaJuegoPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentanaJuegoPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaJuegoPrincipal().setVisible(true);
            }
        });
    }
    
    // Métodos de InterfazVista
    @Override
    public void setControlador(Controlador controlador) {
        volver.addActionListener(controlador);
        guardar.addActionListener(controlador);
        flechaNorte.addActionListener(controlador);
        flechaSur.addActionListener(controlador);
        flechaEste.addActionListener(controlador);
        flechaOeste.addActionListener(controlador);
    }
    
    
    @Override
    public void arrancar() {
        // Visualizo la ventana
        setVisible(true);
    }
    
    
    @Override
    public void cerrar () {
        dispose();
    }
    
    // Métodos de InterfazJuegoPrincipal
    @Override
    public void setSaludo (String string) {
        saludo.setText("Hola "+string);
    }
    
    
    @Override
    public void setTituloPartida (int nivel) {
        String stringNivel = "";
        if (nivel ==1) stringNivel = "Facil";
        else if (nivel == 2) stringNivel = "Moderada";
        else if (nivel == 3) stringNivel = "Dificil";
        partida.setText("Partida "+stringNivel);
    }

    
    @Override
    public void mostrarSorpresaAtravesada (String nombreSorpresa) {
        String mensaje = "";
        if (nombreSorpresa.equals("SorpresaFavorable"))
            mensaje = "Acabas de encontrar una Sorpresa Favorable. Enhorabuena!";
        else if (nombreSorpresa.equals("SorpresaDesfavorable"))
            mensaje = "Oh no! Acabas de encontrar una Sorpresa Desfavorable.";
        else if (nombreSorpresa.equals("CambioDeVehiculo"))
            mensaje = "Acabas de encontrar un Cambio de Vehiculo.";
        JOptionPane.showMessageDialog (this, mensaje);
    }
    
    
    @Override
    public void setMovimientosMaximos (int movimientos) {
        String stringMovimientos = Integer.toString(movimientos);
        movimientosMaximos.setText("Movs. maximos: " + stringMovimientos);
    }
    
    @Override
    public void setMovimientosActuales (int movimientos) {
        String stringMovimientos = Integer.toString(movimientos);
        movimientosActuales.setText("Movs. actuales: " + stringMovimientos);
    }
    
    @Override
    public void setVehiculo (String string) {
        vehiculoActual.setText("Vehiculo: " + string);
    }
    
    @Override
    public void setPuntaje (int puntajeJugador) {
        String stringPuntaje = Integer.toString(puntajeJugador);
        puntaje.setText("Puntaje: " + stringPuntaje);
    }
    
    @Override
    // Metodo que genera todos los componentes del panel principal de la ciudad
    public void inicializarCiudad (int callesHorizontales, int callesVerticales) {
        ciudad.inicializar(callesHorizontales, callesVerticales);
        
        jPanel2.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = GridBagConstraints.BOTH;
        gbc.weightx = 1;
        gbc.weighty = 1;
        jPanel2.add(ciudad, gbc);
       
    }

    @Override
    public void agregarObstruccionesEnCalle(int x, int y, List<String> nombresObstrucciones) {
        for (int i = 0; i < nombresObstrucciones.size(); i++) {
            String obstruccion = nombresObstrucciones.get(i);
            ciudad.agregarObstruccion (obstruccion, x, y);
        }
    }        

    @Override
    public void colocarVehiculoEnPosicion(int x, int y, String tipoDeVehiculo) {
        ciudad.colocarVehiculoEnPosicion (x, y, tipoDeVehiculo);
    }
    
    @Override
    public void transparentarPanel(int posicionX, int posicionY) {
        ciudad.transparentarPanel(posicionX, posicionY);
    }
    
    @Override
    public void colocarLineaDeLlegada(int x, int y) {
        ciudad.colocarLineaDeLlegada (x, y);

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton flechaEste;
    private javax.swing.JButton flechaNorte;
    private javax.swing.JButton flechaOeste;
    private javax.swing.JButton flechaSur;
    private javax.swing.JButton guardar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel movimientosActuales;
    private javax.swing.JLabel movimientosMaximos;
    private javax.swing.JLabel partida;
    private javax.swing.JLabel puntaje;
    private javax.swing.JLabel saludo;
    private javax.swing.JLabel vehiculoActual;
    private javax.swing.JButton volver;
    // End of variables declaration//GEN-END:variables

}
